//手机号验证
function verifyPhone(phone,callback) {
    //拼装 json
    let json = {"phone":phone};
    $.getJSON("http://localhost:7777/hy-frontuser-consumer/ums_member/phoneVerify.action",json,function (res) {
        callback(res);
    });
};

// 短信验证码发送
function sendSms(data) {
    $.ajax({
        type: "Get",
        url: "http://127.0.0.1:7777/hy-frontuser-consumer/ums_member/send.action",
        data: data,
        dataType: "json",
        async: false,
        success: function (res) {
            let class1 = ".code-box";
            if (res.code == 100 ) {
                ShowTips("<span style='color:mediumvioletred'>验证码已发送请查收</span>", ".code-box");
                counter = 0;
                $("#getcode").hide();
                $("#regetcode").html("90");
                $("#prompt_info").show();
                $("#phoneCode").focus();
                interval = window.setInterval(intervalFunc, 1000);
            }
            else if(res.code==102){
                ShowTips("<span style='color:mediumvioletred'>发送失败</span>",class1);
                /* if (res.DataStatus == 1026) {      // 需要图片验证码
                     $("#phoneVerifyBox").show();
                     $("#phonePicCode").focus();
                     class1 = ".verify-box1";
                 }
                 else if (res.DataStatus == 1002) {     // 手机号格式不正确
                     $("#phone").focus();
                     class1 = ".phone-box";
                 }
                 else if (res.DataStatus == 1012) {     // 图片验证码不正确
                     $("#phoneVerifyBox").show();
                     RefreshImage2('imgCaptcha1','phone');
                     $("#phonePicCode").focus();
                     class1 = ".verify-box1";
                 }
                 else if (res.DataStatus == 1003) {     // 短信验证码发送过于频繁
                     class1 = ".code-box";
                 }
                 if (res.DataStatus != 0) {
                     ShowTips(res.ErrMsg || data.Message, class1);
                 }*/
            }else{
                ShowTips("<span style='color:mediumvioletred'>验证码未失效</span>",class1);
            }
        }
    });
}

//绑定手机
function bind_Phone(data) {
    //获取登录地址
    $.ajax({
        type: "get",
        url: "https://restapi.amap.com/v3/ip?parameters&key=dde806404afaf4ca0ce23f829d6946a5&output=JSON",
        dataType: "json",
        success: function (res) {
            //省份
            var province = res.province;
            //城市
            var city = res.city;
            if(res.status == 1){  //登录地址获取成功
                //password: pwd, //密码没有加
                data.province = province;
                data.city = city;
                $.ajax({
                    type: "POST",
                    async: false,
                    contentType:'application/json;charset=utf-8;',
                    dataType: "json",
                    url: "http://127.0.0.1:7777/hy-frontuser-consumer/ums_member/third_reg.action",
                    data: JSON.stringify(data),
                    success: function (res) {
                        /**
                         * 响应编码 100-请求成功 101-请求异常 102-无数据 103-未登录 104-请求失败 105-授权失败
                         */
                        if (res.code == 100){
                            //绑定成功  跳转主页(后台返回地址)
                            window.location.href = res.redirectUrl;
                        }else{ //绑定失败
                            //提示文本
                            ShowTips(res.message, ".code-box");
                        };
                    }
                });
            }
        }
    });
};